package cn.zzdt4j.server.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Database configuration.
 *
 * <p> Quoted from org.apache.shenyu.admin.config.DataBaseConfiguration
 *
 * @author by <a href="mailto:ligang941012@gmail.com">gang.Li</a>
 * @since 2023/10/28 21:34
 */
@Configuration
public class DataBaseConfiguration {

    @Bean
    @ConditionalOnMissingBean(value = DataBaseProperties.class)
    public DataBaseProperties dataBaseProperties(@Value("${zzdt4j.database.dialect:h2}") String dialect,
                                                 @Value("${zzdt4j.database.init_script:sql-script/h2/schema.sql}") String initScript,
                                                 @Value("${zzdt4j.database.init_enable:false}") Boolean initEnable) {
        DataBaseProperties dataSourceProperties = new DataBaseProperties();
        dataSourceProperties.setDialect(dialect);
        dataSourceProperties.setInitScript(initScript);
        dataSourceProperties.setInitEnable(initEnable);
        return dataSourceProperties;
    }
}
